package com.sasu.university_data.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器规则配置类
 *
 * @author qionglan
 * @version 1.0.0
 * @date 2024/06/13 15:48:13
 * @see HandlerInterceptor
 * @since 1.0.0
 */

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession().getAttribute("username")==null){
            //重新定位访问地址
            response.sendRedirect("/html/login.html");
            return false;
        }
        return true;
    }
}
